﻿using System;
using System.Data;
using System.Configuration;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
using System.ComponentModel;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Base class for all <see cref="Grid"/> columns.
	/// </summary>
	public abstract class BaseGridColumn
	{
		#region PUBLIC
		#region INIT
		/// <summary>
		/// Ctor.
		/// </summary>
		public BaseGridColumn()
		{
			this.Header = new HeaderElement();
			this.Footer = new StyledLabelElement();
			this.SortExpression = "";
			this.Visibility = GridColumnVisibility.Always;
		}
		#endregion
		#region EVENTS
		#endregion
		#region PROPS
		/// <summary>
		/// CSS and label applied to the header cell.
		/// </summary>
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		public StyledLabelElement Header { get; set; }
		/// <summary>
		/// CSS and label applied to the footer cell.
		/// </summary>
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		public StyledLabelElement Footer { get; set; }
		/// <summary>
		/// CSS applied to the cell of a view item.
		/// </summary>
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		public StyledElement ViewCell { get { return _viewCell; } }
		/// <summary>
		/// CSS applied to the cell of an edit item.
		/// </summary>
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		public StyledElement EditCell { get { return _editCell; } }
		/// <summary>
		/// The value to set the <see cref="Repeater.SortExpression"/> to when clicking the header of this column.
		/// </summary>
		[DefaultValue("")]
		public string SortExpression { get; set; }
		/// <summary>
		/// Gets or sets a value which specifies when this column is visible.
		/// </summary>
		[DefaultValue(GridColumnVisibility.Always)]
		public GridColumnVisibility Visibility { get; set; }
		#endregion
		#region METHODS
		/// <summary>
		/// Creates the header controls.
		/// </summary>
		/// <param name="container"></param>
		/// <param name="owner"></param>
		public virtual void CreateHeader(Control container, Grid owner)
		{
			if (!string.IsNullOrEmpty(this.SortExpression))
			{
				LinkButton btn = new LinkButton
				{
					ID = "btn" + this.SortExpression,
				};
				container.Controls.Add(btn);
				btn.Click.Client = string.Format(
					"$GetObject(\"{0}\").FireCommand(\"Sort\", \"{1}\");",
					owner.ClientID,
					this.SortExpression);
				container = btn;
			}

			Header.InstantiateIn(container);
		}
		/// <summary>
		/// Creates the footer controls.
		/// </summary>
		/// <param name="container"></param>
		/// <param name="owner"></param>
		public virtual void CreateFooter(Control container, Grid owner)
		{
			if (!string.IsNullOrEmpty(this.SortExpression))
			{
				LinkButton btn = new LinkButton
				{
					ID = "btn" + this.SortExpression,
				};
				btn.Click.Client = string.Format(
					"$GetObject(\"{0}\").FireCommand(\"Sort\", \"{1}\");",
					owner.ClientID,
					this.SortExpression);
				container = btn;
			}

			Footer.InstantiateIn(container);
		}
		/// <summary>
		/// When implemented, creates the view item controls.
		/// </summary>
		/// <param name="container"></param>
		/// <param name="owner"></param>
		public abstract void CreateViewItem(Control container, Grid owner);
		/// <summary>
		/// When implemented, creates the edit item controls.
		/// </summary>
		/// <param name="container"></param>
		/// <param name="owner"></param>
		public abstract void CreateEditItem(Control container, Grid owner);
		#endregion
		#endregion
		#region INTERNAL
		#region CONST/STATIC
		#endregion
		#region VARS
		#endregion
		#region PROPS
		#endregion
		#region METHODS
		#region INIT
		StyledElement _viewCell = new StyledElement(),
			_editCell = new StyledElement();
		#endregion
		#region DATA
		#endregion
		#region HANDLERS
		#endregion
		#endregion
		#endregion



	}
}